import { http } from "@/utils/http";

/** 查询条件（分页） */
export interface ReformMainQuery extends BasePageQuery {
  code?: string;
  inspectors?: string;
  reformStatus?: string;
  questionTitle?: string; // 添加 questionTitle 属性
  dutyDeptId?: number;
  issueDeptId?: number;
  curDealDeptId?: number;
}

/** 返回的单条记录类型 */
export interface ReformMainPageResponse {
  reformId: number;
  code: string;
  relatedQuestionId: number;
  questionSourceName: string;
  checkDate: string;
  inspectors: string;
  issueDate: string;
  requestFeedbackDate: string;
  questionTitle: string;
  reformTitle: string;
  issueDeptId: number;
  dutyDeptId: number;
  curDealDeptId: number;
  reformRequirement: string;
  requireDefineCause: string;
  requireDefineAction: string;
  directCause: string;
  rootCause: string;
  causeEvalerName: string;
  causeEvalTime: string;
  correctiveDeadline: string;
  precautionDeadline: string;
  actionMakerName: string;
  actionMakeTime: string;
  actionIsOk: string;
  actionEval: string;
  actionEvalerName: string;
  actionEvalTime: string;
  correctiveActionProofUploaderName: string;
  correctiveActionProofUploadTime: string;
  correctiveActionProofEvalIsOk: string;
  correctiveActionProofEvalerName: string;
  correctiveActionProofEvalTime: string;
  precautionActionProofUploaderName: string;
  precautionActionProofUploadTime: string;
  precautionActionProofEvalIsOk: string;
  precautionActionProofEvalerName: string;
  precautionActionProofEvalTime: string;
  proofEvalIsOk: string;
  proofEvalerName: string;
  proofEvalTime: string;
  reformStatus: string;
  reformType: string;
  relateId: number;
  relateCode: string;
  terminalType: string;
  isReport: string;
  isFile: string;
  requireDefineCauseRoot: string;
  requireDefineActionPre: string;
  isShareReport: string;
  createTime: string;
  issueDeptName: string;
  dutyDeptName: string;
  correctiveAction: string;
  precautionAction: string;
  inspectionCheckId: number;
  problemDetail: string;
  problemSource: string;
  basis: string;
  rectificationResult?: string;
  severity?: number;
  possibility?: number;
  rectificationOpinion?: string;
}

/** 新增整改通知书命令 */
export interface AddReformMainCommand {
  reformId?: number;
  code?: string;
  relatedQuestionId?: number;
  questionSourceName?: string;
  checkDate?: string | Date;
  inspectors?: string;
  issueDate?: string | Date;
  requestFeedbackDate?: string | Date;
  questionTitle?: string;
  reformTitle?: string;
  issueDeptId?: number;
  dutyDeptId?: number;
  curDealDeptId?: number;
  reformRequirement?: string;
  requireDefineCause?: string;
  requireDefineAction?: string;
  directCause?: string;
  rootCause?: string;
  causeEvalerName?: string;
  causeEvalTime?: string | Date;
  correctiveDeadline?: string | Date;
  precautionDeadline?: string | Date;
  actionMakerName?: string;
  actionMakeTime?: string | Date;
  actionIsOk?: string;
  actionEval?: string;
  actionEvalerName?: string;
  actionEvalTime?: string | Date;
  correctiveActionProofUploaderName?: string;
  correctiveActionProofUploadTime?: string | Date;
  correctiveActionProofEvalIsOk?: string;
  correctiveActionProofEvalerName?: string;
  correctiveActionProofEvalTime?: string | Date;
  precautionActionProofUploaderName?: string;
  precautionActionProofUploadTime?: string | Date;
  precautionActionProofEvalIsOk?: string;
  precautionActionProofEvalerName?: string;
  precautionActionProofEvalTime?: string | Date;
  proofEvalIsOk?: string;
  proofEvalerName?: string;
  proofEvalTime?: string | Date;
  reformStatus?: string;
  reformType?: string;
  relateId?: number;
  relateCode?: string;
  terminalType?: string;
  isReport?: string;
  isFile?: string;
  requireDefineCauseRoot?: string;
  requireDefineActionPre?: string;
  isShareReport?: string;
  inspectionCheckId?: number;
  deleted?: boolean;
  creatorId?: number;
  createTime?: string | Date;
  correctiveActionProof?: string;
  precautionActionProof?: string;
  // 允许附加其他属性
  [key: string]: any;
}


/** 修改整改通知书命令 */
export interface UpdateReformMainCommand extends AddReformMainCommand {
  reformId?: number;
  directCause?: string;
  rootCause?: string;
  basis?: string;
  correctiveAction?: string;
  precautionAction?: string;
  causeEvalerName?: string;
  causeEvalTime?: string;
  rectificationOpinion?: string;

  actionEval?: string;
  severity?: number;
  possibility?: number;
  actionEvalerName?: string;
  actionEvalTime?: string;

}

/** 整改详情实体 */
export interface SirReformDetailEntity {
  reformId: number;
  nonConfirmDesc: string;
  correctiveActionProof: string;
  precautionActionProof: string;
  correctiveActionProofEvalMemo: string;
  proof: string;
  proofEvalMemo: string;
  oldCorrectiveActionProof: string;
  oldPrecautionActionProof: string;
}

/** 获取分页列表 */
export function getReformMainListApi(params: ReformMainQuery) {
  return http.request<ResponseData<PageDTO<ReformMainPageResponse>>>(
    "get",
    "/airport/reformMain/list",
    {
      params
    }
  );
}

/** 导出 Excel */
export function exportReformMainExcelApi(
  params: ReformMainQuery,
  fileName: string
) {
  return http.download("/airport/reformMain/excel", fileName, {
    params
  });
}

/** 获取详情 */
export function getReformMainDetailApi(reformId: number) {
  return http.request<ResponseData<ReformMainPageResponse>>(
    "get",
    `/airport/reformMain/${reformId}`
  );
}

/** 新增 */
export function addReformMainApi(data: AddReformMainCommand) {
  return http.request("post", "/airport/reformMain", { data });
}

/** 修改 */
export function updateReformMainApi(data: UpdateReformMainCommand) {
  return http.request("put", "/airport/reformMain", { data });
}

/** 删除 */
export function deleteReformMainApi(ids: number[]) {
  return http.request("delete", "/airport/reformMain", {
    params: { ids }
  });
}

/** 根据整改ID查询整改详情 */
export function getReformDetailApi(reformId: number) {
  return http.request<ResponseData<SirReformDetailEntity>>(
    "get",
    `/airport/reformMain/reformDetail/${reformId}`
  );
}
